//
//  RHMoreProductVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/11/30.
//

#import "RHMoreProductVC.h"
#import "RHMorePoductCell.h"
#import "RHProductIntroduceVC.h"
@interface RHMoreProductVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;

@property (nonatomic ,strong) NSArray *dataArr;
@end

@implementation RHMoreProductVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"更多产品".rh_localized;
    self.dataArr = @[@{CellTitle:@"Estand",CellIcon:@"product_Estand",@"isNew":@(1)},
                     @{CellTitle:@"Xcellent",CellIcon:@"product_Xcellent",@"isNew":@(0)},
                     @{CellTitle:@"Xcellent",CellIcon:@"product_Xcellent_01",@"isNew":@(0)},
                     @{CellTitle:@"Xcellent",CellIcon:@"product_Xcellent_02",@"isNew":@(0)},
                     @{CellTitle:@"Ebrick",CellIcon:@"product_Ebrick",@"isNew":@(0)},
                     @{CellTitle:@"Xtreme",CellIcon:@"product_Xtreme LV",@"isNew":@(0)},
                     @{CellTitle:@"Smart pile",CellIcon:@"product_Smart pile",@"isNew":@(0)},];
    [self setupUI];
}

-(void)setupUI
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.backgroundColor = CFTabViewBgColor;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [_collectionView registerClass:[RHMorePoductCell class] forCellWithReuseIdentifier:@"RHMorePoductCell"];
    [self.view addSubview:_collectionView];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}
#pragma mark  设置CollectionView的组数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    

    RHMorePoductCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RHMorePoductCell" forIndexPath:indexPath];
    cell.dic = self.dataArr[indexPath.item];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat itemSize = (kUI_WINDOW_W-3*15)/2;
    return CGSizeMake(itemSize, itemSize);
}

#pragma mark  设置CollectionViewCell是否可以被点击
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
//列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}
//行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
   
    return 15;
}

//定义每个Section的四边间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(15, 15, 15, 15);//分别为上、左、下、右
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[RHProductIntroduceVC new] animated:YES];
}
@end
